package com.yifeng.repo.toolkit.elasticsearch.configure;

import com.yifeng.repo.toolkit.elasticsearch.ElasticSearchClient;
import com.yifeng.repo.toolkit.elasticsearch.ElasticSearchDataWorker;
import com.yifeng.repo.toolkit.elasticsearch.ElasticSearchIndexWorker;
import com.yifeng.repo.toolkit.elasticsearch.ElasticSearchQueryWorker;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * Created by daibing on 2021/5/17.
 */
@Configuration
@ConditionalOnClass({ElasticsearchProperties.class})
@EnableConfigurationProperties(ElasticsearchProperties.class)
public class ElasticsearchConfiguration {
    private final ElasticsearchProperties properties;

    public ElasticsearchConfiguration(ElasticsearchProperties properties) {
        this.properties = properties;
    }

    @Bean(initMethod = "init", destroyMethod = "destroy")
    public ElasticSearchClient elasticSearchClient() {
        return new ElasticSearchClient(properties);
    }

    @Bean
    public ElasticSearchIndexWorker elasticSearchIndexWorker(ElasticSearchClient client) {
        return new ElasticSearchIndexWorker(client);
    }

    @Bean
    public ElasticSearchDataWorker elasticSearchDataWorker(ElasticSearchClient client) {
        return new ElasticSearchDataWorker(client);
    }

    @Bean
    public ElasticSearchQueryWorker elasticSearchQueryWorker(ElasticSearchClient client) {
        return new ElasticSearchQueryWorker(client);
    }

}
